<?php
use \Workerman\Autoloader;

require_once __DIR__ . '/../../../../../Workerman/Autoloader.php';
require_once __DIR__.'/../../../Config/Const.php';
Autoloader::setRootPath(__DIR__.'/../../..');

$page_groupId = GROUP_SYS_ANNOUNCEMENT_MNG;
$page_pageId = PAGE_ANNOUNCEMENT_TO_RESTAURANT;

require "../framepages/moudle_base.php";

$mode = $_POST['mode'];
$result = 'normal';
if ($mode == 'send_announcement') {
    $announcement_content = $_POST['announcement_content'];
    if (!$announcement_content) {
        $result = 'err_noAnnouc';
    } else {
        $system_announcement_to_restaurant_record = new \Data\System_announcement_to_restaurant(array());
        $system_announcement_to_restaurant_record->setANNOUNCEMENT_CONTENT($announcement_content);
        $system_announcement_to_restaurant_record->setCREATED_BY($_SESSION['USER']);
        \Data\System_announcement_to_restaurant_DAO::insert($system_announcement_to_restaurant_record);
        $result = 'succ_sendAnnouc';
    }
}

?>
<div class="main-content" style="margin-left: 10px;">
    <div>
        <form action="" method="post">
            <input type="hidden" name="mode" id="mode" value="send_announcement">
            <div>
                <div>
                    <div>
                        <span style="font-size: 18px">广播内容</span>
                    </div>
                    <br>
                    <div>
                        <textarea cols="50" rows="10" id="announcement_content" name="announcement_content" ><?php echo $announcement_content ?></textarea>
                    </div>
                    <div>
                        <input type="submit" class="btn btn-danger" value="发送">
                    </div>
                </div>
            </div>
        </form>
    </div>

    <?php
    require "../framepages/footer.php";
    ?>
</div>
</div>
<script src="../lib/bootstrap/js/bootstrap.js"></script>
<script>
    function init() {
        var msg = "<?php echo $result ?>";
        if (msg == 'err_noAnnouc') {
            alert('广播内容不能为空');
        } else if (msg == 'succ_sendAnnouc') {
            alert('发送成功');
        }
    }

</script>
</body>
</html>
